﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Frogism.Web.Controllers;
using System.Web.Mvc;

namespace Frogism.Tests {
  [TestFixture]
  public class TestBookController {

    [Test]
    public void BookControllerFinished() {
      Frogism.Web.Controllers.BookController bc = new Frogism.Web.Controllers.BookController(mock);
//      bc.Finished();

      ViewResult result = bc.Finished();
      Assert.AreEqual("Index",result.ViewName);
      Assert.AreEqual(typeof(Frogism.Web.Models.BookViewData), result.ViewData.Model.GetType());

      var obj = (Frogism.Web.Models.BookViewData)result.ViewData.Model;

      Assert.AreEqual(1, obj.Books.Count());
      Assert.AreEqual(bookFinished, obj.Books.First());

    }
    MockBookManager mock;
    Core.Book bookFinished;
    Core.Book bookNotFinished;
    [SetUp]
    public void Setup() {
      mock = new MockBookManager();
      bookFinished = new Core.Book() { Id = 0, Title = "Test book", LastPageNumber = 100, IsFinished = true, GoalYear = 2008 };
      bookNotFinished = new Core.Book() { Id = 1, Title = "Test book", LastPageNumber = 100, IsFinished = false, GoalYear = 2008 };
      mock.list.Add(bookFinished);
      mock.list.Add(bookNotFinished);
    }
    [Test]
    public void TestMockBookManager() {

      BookController bc = new BookController(mock);
      Assert.AreEqual(mock.list, mock.GetAll());
      Assert.AreEqual(mock.list[0].Title, mock.GetAll().First().Title);
    }
    
  }
  public class MockBookManager :  Core.IBookManager {
    public System.Collections.ObjectModel.Collection<Frogism.Core.IBook> list = new System.Collections.ObjectModel.Collection<Frogism.Core.IBook>();
    public IEnumerable<Frogism.Core.IBook> GetAll()
    {
      return list;
    }
    public void DeleteRead(Core.IRead read) {
      throw new NotImplementedException();
    }

    public Frogism.Core.IRead GetOrCreateTodaysRead(Frogism.Core.IBook book) {
      throw new NotImplementedException();
    }

    public IEnumerable<Frogism.Core.IBook> GetPublicReading() {
      throw new NotImplementedException();
    }

    public Frogism.Core.IRead GetReadById(Frogism.Core.IBook book, int readId) {
      throw new NotImplementedException();
    }

    public System.Collections.ObjectModel.Collection<Frogism.Core.IBook> GetReading() {
      throw new NotImplementedException();
    }

    public Frogism.Core.ILoader<Frogism.Core.Book, Frogism.Core.IBook> Loader {
      get { throw new NotImplementedException(); }
    }

    public void Update(Frogism.Core.IBook book) {
      throw new NotImplementedException();
    }

    public void UpdateRead(Frogism.Core.IBook book, Frogism.Core.IRead read) {
      throw new NotImplementedException();
    }

    public System.Collections.ObjectModel.Collection<int> YearList {
      get { throw new NotImplementedException(); }
    }

    public Frogism.Core.IBook Get(int id) {
      throw new NotImplementedException();
    }



    public IEnumerable<Frogism.Core.IBook> GetFinished() {
      throw new NotImplementedException();
    }
  }
}
